home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 21
/
AMIGAplus Sonderheft 21 (1999)(ICP)(DE)[!].iso
/
PublicDomain
/
System
/
recoverdeldir
/
c
/
SFSDeldirName.c
< prev
Wrap
C/C++ Source or Header
|
1999-08-23
|
3KB
|
127 lines
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <utility/tagitem.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <stdio.h>
#include "fs/packets.h"
#include "fs/query.h"
#include "fs/nodes.h"
// sfs special, doesn't work with 1.13, methinks
// SFS 1.53: works
long __saveds progstart (void)
{
static const char VersionString[] = {"\0$VER: SFSDeldirName 1.2 " __AMIGADATE__" ©1999 Thomas Krafzik\r\n"};
UBYTE template[] = "DEVICE/A\n";
LONG error = RETURN_OK;
char *arg = NULL;
struct RDArgs *rdargs;
struct ExecBase *SysBase;
struct DosLibrary *DOSBase;
// Zuerst SysBase, sonst geht alles schief
SysBase = * (struct ExecBase **) 4L;
if (DOSBase = (struct DosLibrary *) OpenLibrary ("dos.library", 37L))
{
if (rdargs = ReadArgs (template, (LONG *) &arg, 0))
{
struct MsgPort *msgport;
struct DosList *doslist;
UBYTE *devname = arg;
// eventuell eingegebenen Doppelpunkt eliminieren
// in der DosList sind die Geräte nur ohne Doppelpunkt anzutreffen
while (*devname)
{
if (*devname == ':')
{
*devname = 0;
break;
}
devname++;
}
// DosList vorbereiten
doslist = LockDosList (LDF_DEVICES | LDF_READ);
// Gerät vorhanden ?
if (doslist = FindDosEntry (doslist, arg, LDF_DEVICES))
{
struct TagItem tags[] = {ASQ_HAS_RECYCLED, 0};
// MsgPort des FileSystems
msgport = doslist->dol_Task;
// DosList wieder freigeben
UnLockDosList (LDF_DEVICES | LDF_READ);
// Packet synchron verschicken: ACTION_SFS_QUERY
if (DoPkt (msgport, ACTION_SFS_QUERY, (LONG) &tags, 0, 0, 0, 0))
{
// Etwas dabei herausgekommen ?
if (tags[0].ti_Data)
{
BPTR lock;
char buffer [512];
// Packet synchron verschicken: ACTION_SFS_LOCATE_OBJECT
if (lock = DoPkt (msgport, ACTION_SFS_LOCATE_OBJECT, RECYCLEDNODE, SHARED_LOCK, 0, 0, 0))
{
// Mit dem Lock können wir nicht viel anfangen,
// also holen wir uns den passenden Namen
NameFromLock (MKBADDR (lock), buffer, 256);
Printf ("%s", FilePart (buffer));
}
else
{
Printf ("0");
error = RETURN_WARN;
}
}
else
{
Printf ("0");
error = RETURN_WARN;
}
}
else
{
Printf ("-1");
error = RETURN_ERROR;
}
}
else
{
UnLockDosList (LDF_DEVICES | LDF_READ);
Printf ("-1");
error = RETURN_ERROR;
}
// DosList wieder freigeben
FreeArgs (rdargs);
}
else
{
Printf ("-1");
error = RETURN_FAIL;
}
CloseLibrary ((struct Library *) DOSBase);
}
return (error);
}